package unit8.part5;

import javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class AdaptTest {
    public static void main(String[] args) {
        JFrame jFrame = new JFrame("测试事件适配器");
        jFrame.setBounds(100, 100, 500, 500);
        jFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);// 点击关闭按钮时什么也不做

        jFrame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                int r = JOptionPane.showConfirmDialog(null, "是否关闭本窗口？", "是否", JOptionPane.YES_NO_OPTION);
                if (r == 0) {
                    jFrame.dispose();
                    System.exit(0);
                    super.windowClosing(e);
                }
            }
        });

        jFrame.setVisible(true);
    }
}